package canss.webservice.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import canss.supports.basic;
import canss.webservice.service.PortalIntraWebServiceControl;
import canss.webservice.service.PortalIntraWebServiceControlBean;

public class svtAjaxRemoveChannel extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet
{

	private static final long serialVersionUID = 6244649840847503978L;

	public svtAjaxRemoveChannel()
	{
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{
		doPost(request, response);
	}

	PortalIntraWebServiceControl control; // control = (control==null)?new
	// PortalIntraWebServiceControlBean():control;

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");
		StringBuffer retstr = new StringBuffer();
		PrintWriter out = response.getWriter();

		try
		{
			String _pid = request.getParameter("_pid");
			String _index = request.getParameter("_index");

			if (!basic.isEmpty(_pid) && !basic.isEmpty(_index))
			{
				control = (control==null)? new PortalIntraWebServiceControlBean():control;
				/*Boolean ret = */control.removeChannelByPIDIndex(_pid, Integer.parseInt(_index));
			}
		} catch (RuntimeException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			retstr.append(e.toString() + "<br/>");
		}
		out.write(retstr.toString());

		String _rurl = request.getParameter("_rurl");
		if (!basic.isEmpty(_rurl))
		{
			response.sendRedirect(response.encodeRedirectURL(_rurl));
		}
	}
}